//
//  PANavgationVC.m
//  PilotSeries
//
//  Created by 黄立强 on 16/6/30.
//  Copyright © 2016年 leon.huang. All rights reserved.
//

#import "PANavgationVC.h"
#import "PAChartDetailVC.h"
@interface PANavgationVC ()

@end

@implementation PANavgationVC
/**
 * 当第一次使用这个类的时候会调用一次
 */
+ (void)initialize
{
    // 当导航栏用在XMGNavigationController中, appearance设置才会生效
    //    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:[self class], nil];
//    UINavigationBar *bar = [UINavigationBar appearance];
////    [bar setTintColor:[UIColor whiteColor]];
//    [bar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:0.689 green:0.714 blue:0.734 alpha:1.000]]forBarMetrics:UIBarMetricsDefault];
//    
}

- (void)viewDidLoad {
    [super viewDidLoad];

}

/**
 * 可以在这个方法中拦截所有push进来的控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) { // 如果push进来的不是第一个控制器
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"Back" forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"back_normal"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"back_press"] forState:UIControlStateHighlighted];
        button.size = CGSizeMake(70, 30);
        // 让按钮内部的所有内容左对齐
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        //        [button sizeToFit];
        // 让按钮的内容往左边偏移10
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [button setTitleColor:[UIColor colorWithRed:0.000 green:0.478 blue:1.000 alpha:1.000] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        
        // 修改导航栏左边的item
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        
        // 隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    // 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:animated];
    
}

- (void)back
{
//    [PAC]
//    if([self.topViewController isKindOfClass:[PAChartDetailVC class]]){
//        PAChartDetailVC *vc  = (PAChartDetailVC *)self.topViewController;
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"resizeBtn" object:nil userInfo:@{@"cellRow":[NSNumber numberWithInt:vc.cellRow]}];
//    }
    [self popViewControllerAnimated:YES];
}

@end
